<script setup>
import { ref, reactive, getCurrentInstance } from "vue"

const { proxy } = getCurrentInstance()

const wsSendMsg = ref("")
const wsRecvMsg = reactive([])

proxy.wsWrapper.getEmitter().on("ws-message", (msg) => {
  console.log("wsEmitter.on:ws-message", msg)
  wsRecvMsg.push(msg)
})

const onWsSendClick = () => {
  proxy.wsWrapper.send(wsSendMsg.value)
  wsSendMsg.value = ''
}
</script>

<template>
  <div>
    <el-row style="height: 500px" justify="space-between">
      <el-col :span="10">
        Send:
        <textarea class="full-size" v-model="wsSendMsg" />
      </el-col>
      <el-col :span="2">
        <el-button type="primary" @click="onWsSendClick">Send</el-button>
      </el-col>
      <el-col :span="10">
        Recv:
        <textarea class="full-size" :value="wsRecvMsg.join('\n')" disabled />
      </el-col>
    </el-row>
  </div>
</template>

<style lang="scss" scoped>
textarea {
  background: #444;
  color: #fff;
  height: 300px;
  padding: 10px;
  box-sizing: border-box;
  outline: none;
}
</style>
